package entity

import (
	"strconv"
	"time"

	"shqsoft.cn/pasnj/base"
	"shqsoft.cn/pasnj/bi/cube"
)

type INDI_SAVE_ACCO struct {
	ID       int        `gorm:"AUTO_INCREMENT;primary_key;column:ID"`
	Zhanghao string     `gorm:"column:帐号;size:20"`
	Khao     string     `gorm:"column:卡号"`
	Km       string     `gorm:"column:科目"`
	Khwd     string     `gorm:"column:开户网点"`
	Khmc     string     `gorm:"column:客户名称;size:20"`
	Bizhong  string     `gorm:"column:币种;size:20"`
	Khr      *time.Time `gorm:"column:开户日;type:date;"`
	Qxr      *time.Time `gorm:"column:起息日;type:date;"`
	Dqr      *time.Time `gorm:"column:到期日;type:date;"`
	Dqye     *float64   `gorm:"column:当前余额;"`
	Sfzh     string     `gorm:"column:身份证号;size:20"`
	Ccly     string     `gorm:"column:执行利率;size:20"`
	YG1      string     `gorm:"-"`
	ZB1      *float64   `gorm:"-"`
	YG2      string     `gorm:"-"`
	ZB2      *float64   `gorm:"-"`
	YG3      string     `gorm:"-"`
	ZB3      *float64   `gorm:"-"`
	YG4      string     `gorm:"-"`
	ZB4      *float64   `gorm:"-"`
	YG5      string     `gorm:"-"`
	ZB5      *float64   `gorm:"-"`
}

//TableName 卡号表名
func (INDI_SAVE_ACCO) TableName() string {
	return "V_INDI_SAVE_ACCOS"

}

// AfterFind 选择男女
func (c *INDI_SAVE_ACCO) AfterFind() (err error) {
	var share *cube.Share
	share, err = cube.GetShare("indi_acco_divi")
	if err != nil {
		return
	}
	var diviMap map[string]float64
	diviMap, err = share.GetDivision(strconv.Itoa(c.ID))
	if err != nil {
		return
	}
	i := 0
	for k, v := range diviMap {
		val := v
		i++
		switch i {
		case 1:
			c.YG1 = k
			c.ZB1 = &val
		case 2:
			c.YG2 = k
			c.ZB2 = &val
		case 3:
			c.YG3 = k
			c.ZB3 = &val
		case 4:
			c.YG4 = k
			c.ZB4 = &val
		case 5:
			c.YG5 = k
			c.ZB5 = &val
		default:
			break
		}
	}
	return
}

//V_Divi_CxEF 储蓄存款
func INDI_SAVE_ACCOEF() base.EntityFunc {
	return func() interface{} {
		entity := INDI_SAVE_ACCO{}
		return &entity
	}
}

//ZTXMCMXESF 储蓄存款
func INDI_SAVE_ACCOESF() base.EntitiesFunc {
	return func() interface{} {
		var entities []INDI_SAVE_ACCO
		return &entities
	}
}
func init() {
	dao := base.NewDefaultDao(INDI_SAVE_ACCOEF(), INDI_SAVE_ACCOESF(), nil)
	filter := base.DefaultFilter{
		FilterColName: "ID",
		TableName:     "T_INDI_ACCO_DIVI",
		EmidColName:   "emid",
		AcidColName:   "ACID",
		WhereCause:    "ISWO=0 AND WODT IS NULL",
	}
	dao.Fileter = &filter
	base.DaoPoolObj.Put("INDI_SAVE_ACCO", dao)
}
